package com.base.andlanggl.objects

import android.opengl.GLES20
import com.base.andlanggl.data.VertexArray
import com.base.andlanggl.programs.ColorShaderProgram

class Mallet {
    companion object{
        const val POSITION_COMPONENT_COUNT:Int=2 //xy坐标计数
        const val COLOR_COMPONENT_COUNT:Int=3 //颜色坐标计数
        const val STRIDE:Int= (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT)*VertexArray.BYTES_PER_FLOAT //步长
        val VERTEX_DATA:FloatArray=floatArrayOf(
            // Order of coordinates: X, Y, R, G, B
            0f, -0.4f, 0f, 0f, 1f,
            0f,  0.4f, 1f, 0f, 0f
        )
    }

    var vertexArray:VertexArray= VertexArray(VERTEX_DATA)

    fun bindData(colorProgram: ColorShaderProgram){
        vertexArray.setVertexAttribPointer(0,colorProgram.aPositionLocation,
            POSITION_COMPONENT_COUNT, STRIDE)
        vertexArray.setVertexAttribPointer(
            POSITION_COMPONENT_COUNT,colorProgram.aColorLocation,
            COLOR_COMPONENT_COUNT, STRIDE)
    }

    fun draw(){
        GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 2)
    }
}